package com.dylearn.controller;

import com.dylearn.domain.SMSCode;
import com.dylearn.serve.IMsgService;
import com.dylearn.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/msg")
public class MsgController {
    @Autowired
    IMsgService iMsgService;

    //获取手机号验证码
    @GetMapping("/{number}")
    public R getById(@PathVariable String number) throws Exception {
        //String msg = iMsgService.getCode(number);
        String msg = iMsgService.getCacheCode(number);//使用缓存注解
        return new R(true, msg);
    }

    @PostMapping()
    public R getPage(@RequestBody SMSCode smsCode) throws Exception {
        //boolean flag = iMsgService.checkCode(smsCode);
        boolean flag = iMsgService.checkCacheCode(smsCode);//使用缓存注解

        return new R(flag, flag ? "校验数据成功！" : "校验数据失败！");
    }


}
